package com.yejiali.backend.controller;

import com.yejiali.backend.entity.Hospitals;
import com.yejiali.backend.entity.dto.HospitalDTO;
import com.yejiali.backend.response.Response;
import com.yejiali.backend.service.HospitalsService;
import io.lettuce.core.dynamic.annotation.Param;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * (Hospitals)表控制层
 *
 * @author yejiali
 * @since 2025-06-05 16:56:36
 */
@RestController
@RequestMapping("hospitals")
@Tag(name = "医疗机构管理", description = "合作医疗机构")
public class HospitalsController {

    @Autowired
    private HospitalsService hospitalsService;

    /**
     * 初始数据，分页显示
     */
    @GetMapping("/initList")
    @Operation(summary = "医疗机构初始信息", description = "医疗机构的分页查询")
    public Response initList(@RequestParam("pageNum") int pageNum,@RequestParam("pageSize") int pageSize) {
        return hospitalsService.initList(pageNum,pageSize);
    }

    /**
     * 按所给条件查询，分页
     * @param
     * @return
     */
    @GetMapping("/search")
    @Operation(summary = "医疗机构信息查询", description = "医疗机构的条件查询")
    public Response search(@RequestParam(required = false) String name,
                           @RequestParam(required = false) String level,
                           @RequestParam(required = false) String type,
                           @RequestParam(required = false) String status,
                           @RequestParam("pageNum") int pageNum,
                           @RequestParam("pageSize") int pageSize) {
        return hospitalsService.search(name,level,type,status,pageNum,pageSize);
    }

    /**
     * 新增医疗机构
     * @param
     * @return
     */
    @PostMapping("/add")
    @Operation(summary = "医疗机构信息新增", description = "医疗机构的新增")
    public Response add(@RequestBody HospitalDTO hospitalDTO){
        return hospitalsService.add(hospitalDTO);
    }

    /**
     * 修改医疗机构
     * @param
     * @return
     */
    @PutMapping("/update")
    @Operation(summary = "医疗机构信息修改", description = "医疗机构的修改")
    public Response update(@RequestBody Hospitals hospitals){
        return hospitalsService.updateInfo(hospitals);
    }

    /**
     * 删除医疗机构
     * @param
     * @return
     */
    @DeleteMapping("/delete")
    @Operation(summary = "医疗机构信息删除", description = "医疗机构的删除")
    public Response delete(@RequestParam("id") Integer id){
        return hospitalsService.delete(id);
    }



}

